package com.echovin.esb.gateway.mapper;

import com.echovin.esb.gateway.model.GatewayIPLimitApi;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GatewayIPLimitMapper {
    @Select("select * from GATEWAY_IP_LIMIT_API where POLICY_TYPE=#{POLICY_TYPE}")
    List<GatewayIPLimitApi>getIPLimits(Integer POLICY_TYPE);

    @SelectKey(keyProperty = "record.id", resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Options(keyProperty = "record.id", useGeneratedKeys = true)
    @Insert("insert into GATEWAY_IP_LIMIT_API(ID,SERVICE_ID,POLICY_TYPE,IP_ADDRESS,CREATER,CREATE_TIME) " +
            "values(#{record.id},#{record.serviceId},#{record.policyType},#{record.ipAddress},#{record.creater},#{record.createTime})")
    int insert(@Param("record") GatewayIPLimitApi record);

    @Update("update GATEWAY_IP_LIMIT_API set IS_DELETE = 1, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where SERVICE_ID = #{record.serviceId}")
    int delete(GatewayIPLimitApi record);

    @Update("update GATEWAY_IP_LIMIT_API set POLICY_TYPE = #{record.policyType}, IP_ADDRESS = #{record.ipAddress}, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ID = #{record.id}")
    int update(GatewayIPLimitApi record);
}
